<template>
  <div>
    <table v-if="list.length && withdraw" class="cs-detail-card">
      <tr>
        <td>魅力等级：{{ list[list.length - 1].mLevel }}</td>
        <td>文字聊天获得积分：{{ withdraw.chatConsume / 100 }}</td>
        <td>收徒奖励积分：{{ withdraw.divideConsume / 100 }}</td>
      </tr>
      <tr>
        <td>魅力值：{{ list[list.length - 1].mCoins }}</td>
        <td>语音聊天获得积分：{{ withdraw.voiceConsume / 100 }}</td>
        <td>收徒分成积分：{{ withdraw.prenticeConsume / 100 }}</td>
      </tr>
      <tr>
        <td>
          累计提现金额：{{ list[list.length - 1].withdrawalMoney / 10000 }}
        </td>
        <td>视频聊天获得积分：{{ withdraw.videoConsume / 100 }}</td>
      </tr>
      <tr>
        <td>累计提现次数：{{ withdrawList.total }}</td>
        <td>收礼获得积分：{{ withdraw.giftConsume / 100 }}</td>
      </tr>
      <tr>
        <td>累计获得积分：{{ withdraw.scoreTotal / 100 }}</td>
      </tr>
      <tr>
        <td>当前积分：{{ detail.coins / 100 }}</td>
      </tr>
    </table>

    <div class="cs-filter-container">
      <el-select v-model="listQuery.status" placeholder="当前状态">
        <el-option label="待审核" :value="0" />
        <el-option label="提现失败" :value="1" />
        <el-option label="提现成功" :value="2" />
        <el-option label="拒绝提现" :value="3" />
      </el-select>
      <el-date-picker
        v-model="daterangeValue"
        :picker-options="daterangePickerOptions"
        type="daterange"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="起始时间"
        end-placeholder="结束时间"
        value-format="yyyy-MM-dd"
        @change="daterangeChanged"
      />
      <el-button
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="getWithdraw"
      >
        搜索
      </el-button>
      <el-button
        type="info"
        size="small"
        icon="el-icon-refresh-right"
        @click="resetFilter"
      >
        重置
      </el-button>
    </div>
    <div class="cs-filter-result">
      <el-table
        v-loading="listLoading"
        :data="withdrawList.userWithdrawList"
        border
        fit
        size="small"
        highlight-current-row
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
      >
        >
        <el-table-column align="center" label="提现时间">
          <template slot-scope="{ row }">{{
            row.applyTime | parseTime
          }}</template>
        </el-table-column>
        <el-table-column align="center" label="操作时间">
          <template slot-scope="{ row }">{{
            row.updateTime | parseTime
          }}</template>
        </el-table-column>
        <el-table-column align="center" label="提现ID">
          <template slot-scope="{ row }">{{ row.withDrawId }}</template>
        </el-table-column>
        <el-table-column align="center" label="提现方式">
          <template slot-scope="{ row }">{{
            row.type === 0 ? '支付宝' : '微信'
          }}</template>
        </el-table-column>
        <el-table-column align="center" label="订单ID">
          <template slot-scope="{ row }">{{ row.alipayOrderId }}</template>
        </el-table-column>
        <el-table-column align="center" label="提现金额">
          <template slot-scope="{ row }">{{ row.amount / 10000 }}</template>
        </el-table-column>
        <el-table-column align="center" label="当前状态">
          <template slot-scope="{ row }">{{
            row.status | filterType
          }}</template>
        </el-table-column>
        <el-table-column align="center" label="备注">
          <template slot-scope="{ row }">{{
            row.refuseReason ? row.refuseReason : row.dealReason
          }}</template>
        </el-table-column>
      </el-table>
      <TablePagination
        :current-page="listQuery.page"
        :limit="listQuery.limit"
        :total="withdrawList.total"
        :loading="listLoading"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChangeOffset"
      />
    </div>
  </div>
</template>
<script>
import TablePagination from '@/components/TablePagination'
import { xhrGetScore } from '@api/account'
import { getWithdrawList } from '@api/withdraw'
export default {
  components: { TablePagination },
  props: {
    list: {
      type: Array,
      default: function() {
        return []
      }
    },
    detail: {
      type: Object,
      default: null
    }
  },
  data() {
    const query = this.$route.query
    return {
      userId: (query && query.id) || null,
      listQuery: {
        status: null
      },
      listLoading: true,
      daterangeValue: [],
      withdraw: null,
      withdrawList: {}
    }
  },
  created() {
    this.getWithdraw()
  },
  methods: {
    doSearch() {
      this.getWithdraw()
    },
    getWithdraw() {
      this.listQuery.userId = this.userId
      xhrGetScore(this.listQuery)
        .then(resp => {
          this.withdraw = resp.data
        })
        .catch(err => {
          this.$message.error(err)
        })

      getWithdrawList(this.listQuery)
        .then(resp => {
          this.withdrawList = resp.data
          this.listLoading = false
        })
        .catch(err => {
          this.listLoading = false
          this.$message.error(err)
        })
    }
  }
}
</script>
